#include<stdio.h>
struct fun
{
	long long a;
	long long b;
	long long limit;
	long long count;
	int flag;
};
struct fun a[10005];
int main()
{
	long long n,i;
	long long l,r,j,m;
	scanf("%lld%lld",&n,&m);getchar();
	for(i=1;i<=n;i++)
	{
		scanf("%lld%lld%lld",&a[i].a , &a[i].b , &a[i].limit);
		l=a[i].a<a[i].b ? a[i].a:a[i].b;
		r=a[i].a>a[i].b ? a[i].a:a[i].b;
		a[i].count=0;a[i].flag=0;
		while(l<=r)
		{
			j=(l+r)/2;
			if(a[i].limit==0)
			{
				a[i].flag=0;
				break;
			}
			a[i].count++;
			if(j<m)
				l=j+1;
			else if(j>m)
				r=j-1;
			else
			{
				a[i].flag=1;
				break;
			}
			if(a[i].count==a[i].limit)
			{
				a[i].flag=0;
				break;
			}
		}
	}
	for(i=1;i<=n;i++)
		if(a[i].flag)
			printf("case %lld: YES %lld\n",i,a[i].count);
		else
			printf("case %lld: NO %lld\n",i,a[i].count);
	return 0;
}
